//
//  LGHelpServicePhoneView.m
//  RedSunDigitalDoctor
//
//  Created by 1234 on 2022/9/28.
//  帮助与客服 -- 拨打电话弹框

#import "LGHelpServicePhoneView.h"

@interface LGHelpServicePhoneView()
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)UILabel *contentLabel;
/**   */
@property (nonatomic , strong)UIView *lineView_H;
/**   */
@property (nonatomic , strong)UIView *lineView_V;
/**   */
@property (nonatomic , strong)UIButton *againBtn;
/**   */
@property (nonatomic , strong)UIButton *cancelBtn;

@end

@implementation LGHelpServicePhoneView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView];
    }
    return self;
}

-(void)setSeviceTime:(NSString *)seviceTime{
    _seviceTime = seviceTime;
    self.contentLabel.text = [NSString stringWithFormat:@"热线服务时间%@，可能出现线路拥挤。建议优先使用自助服务或联系在线客服，更加高效。",seviceTime];
}

-(void)againBtnAction{
    if (self.makePhoneCallAction) {
        self.makePhoneCallAction();
    }
    [self cancelBtnAction];
}

-(void)cancelBtnAction{
    [UIView animateWithDuration:0.4 animations:^{
        self.backgroundColor = [UIColor colorWithString:@"000000" alpha:0];
        self.baseView.transform = CGAffineTransformScale(self.baseView.transform, 0.001, 0.001);
    }completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}

-(void)createSubView{
    self.backgroundColor = [UIColor colorWithString:@"000000" alpha:0];
    [self addSubview:self.baseView];
    [self.baseView addSubview:self.titleLabel];
    [self.baseView addSubview:self.contentLabel];
    [self.baseView addSubview:self.againBtn];
    [self.baseView addSubview:self.cancelBtn];
    [self.baseView addSubview:self.lineView_H];
    [self.baseView addSubview:self.lineView_V];
    [UIView animateWithDuration:0.4 animations:^{
        self.backgroundColor = [UIColor colorWithString:@"000000" alpha:0.6];
        self.baseView.transform = CGAffineTransformScale(self.baseView.transform, 1000, 1000);
    }];
}

-(UIView *)baseView{
    if(!_baseView){
        _baseView = [[UIView alloc]initWithFrame:CGRectMake(viewPix(27), (Screen_H-viewPix(220))/2.0-viewPix(10), Screen_W-viewPix(54), viewPix(220))];
        _baseView.transform = CGAffineTransformScale(_baseView.transform, 0.001, 0.001);
        _baseView.backgroundColor = [UIColor whiteColor];
        _baseView.cornerRidus = 10;
    }
    return _baseView;
}

-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"联系热线客服" colorString:@"#333333" textFont:LGFontWeight(18, UIFontWeightSemibold) textAlignment:NSTextAlignmentCenter lines:1];
        _titleLabel.frame = CGRectMake(0, viewPix(26), Screen_W-viewPix(54), viewPix(25));
    }
    return _titleLabel;
}

-(UILabel *)contentLabel{
    if(!_contentLabel){
        NSString *time = [[NSUserDefaults standardUserDefaults] objectForKey:@"kefuPhoneTime"];
        _contentLabel = [UILabel lableWithText:[NSString stringWithFormat:@"热线服务时间%@，可能出现线路拥挤。建议优先使用自助服务或联系在线客服，更加高效。",time] colorString:@"#333333" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:0];
        _contentLabel.frame = CGRectMake(viewPix(24), viewPix(60), Screen_W-viewPix(102), viewPix(80));
        [_contentLabel lineSpacing:5];
    }
    return _contentLabel;
}

-(UIButton *)againBtn{
    if(!_againBtn){
        _againBtn = [UIButton buttonWithTitle:@"继续拨打" titleFont:LGFontWeight(17, UIFontWeightMedium) textColor:@"#333333" imageName:@""];
        _againBtn.frame = CGRectMake(0, viewPix(164), (Screen_W-viewPix(54))/2.0, viewPix(56));
        [_againBtn addTarget:self action:@selector(againBtnAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _againBtn;
}

-(UIButton *)cancelBtn{
    if(!_cancelBtn){
        _cancelBtn = [UIButton buttonWithTitle:@"返回自助服务" titleFont:LGFontWeight(17, UIFontWeightMedium) textColor:@"#576B95" imageName:@""];
        _cancelBtn.frame = CGRectMake(kMaxX(self.againBtn.frame), viewPix(164), (Screen_W-viewPix(54))/2.0, viewPix(56));
        [_cancelBtn addTarget:self action:@selector(cancelBtnAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _cancelBtn;
}

-(UIView *)lineView_H{
    if(!_lineView_H){
        _lineView_H = [[UIView alloc]initWithFrame:CGRectMake(0, viewPix(164), Screen_W-viewPix(54), 1)];
        _lineView_H.backgroundColor = [UIColor colorWithString:@"#E5E5E5"];
    }
    return _lineView_H;
}

-(UIView *)lineView_V{
    if(!_lineView_V){
        _lineView_V = [[UIView alloc]initWithFrame:CGRectMake((Screen_W-viewPix(54))/2.0, viewPix(164), 1, viewPix(56))];
        _lineView_V.backgroundColor = [UIColor colorWithString:@"#E5E5E5"];
    }
    return _lineView_V;
}


@end
